//封装好mysql方法
import mysql from "mysql";

//创建连接
let conn = mysql.createConnection({
    host: "127.0.0.1",//连接远程服务器
    user: "root",
    password: "",
    port: 3306,
    database: "cuiminxian"
})


//简单的封装
let exec = function (sql, params, callback) {
    conn.query(sql, params,callback)
}


let execAsync = function (sql, params) {
    return new Promise(function (resolve, reject) {
        conn.query(sql, params, (err, row, fields) => {
            if (err) {
                console.log("有错误", err.message)
                reject(err.message)
                return
            }
            resolve(row)
        })
    })
}

module.exports={

    exec,
    execAsync

}


